Problem with logits and labels size in RNN training Need help

by: rmrasul97@gmail.com, 8 years ago


I have used a custom set of data and labels for training an RNN. I have worked through some of the shape and size issues and finally got the training.

The network finishes training without error, however the loss comes out to be either NAN or I get an error like this-

InvalidArgumentError (see above for traceback): logits and labels must be same size: logits_size=[1,2] labels_size=[1,3]

The gist for my code is here-
https://gist.github.com/tu-lee/0af2fd9d8c8d56e2c612e5ea0c3a4639

I believe the problem is in the softmax step, where the predicted labels and the true labels seem to be of different sizes. But I have no idea how I should fix this. Please help.


The full traceback for the error is here-

Traceback (most recent call last):
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonclientsession.py", line 1021, in _do_call
    return fn(*args)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonclientsession.py", line 1003, in _run_fn
    status, run_metadata)
  File "C:UsersraisaAnaconda3libcontextlib.py", line 66, in __exit__
    next(self.gen)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonframeworkerrors_impl.py", line 469, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be same size: logits_size=[1,2] labels_size=[1,3]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_1, Reshape_2)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/raisa/PycharmProjects/RNN_1/test2.py", line 103, in <module>
    train_neural_network(x)
  File "C:/Users/raisa/PycharmProjects/RNN_1/test2.py", line 91, in train_neural_network
    _, c = sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_y})
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonclientsession.py", line 766, in run
    run_metadata_ptr)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonclientsession.py", line 964, in _run
    feed_dict_string, options, run_metadata)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonclientsession.py", line 1014, in _do_run
    target_list, options, run_metadata)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonclientsession.py", line 1034, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be same size: logits_size=[1,2] labels_size=[1,3]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_1, Reshape_2)]]

Caused by op 'SoftmaxCrossEntropyWithLogits', defined at:
  File "C:/Users/raisa/PycharmProjects/RNN_1/test2.py", line 103, in <module>
    train_neural_network(x)
  File "C:/Users/raisa/PycharmProjects/RNN_1/test2.py", line 77, in train_neural_network
    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction, y))
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonopsnn_ops.py", line 1449, in softmax_cross_entropy_with_logits
    precise_logits, labels, name=name)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonopsgen_nn_ops.py", line 2265, in _softmax_cross_entropy_with_logits
    features=features, labels=labels, name=name)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonframeworkop_def_library.py", line 759, in apply_op
    op_def=op_def)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonframeworkops.py", line 2240, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "C:UsersraisaAnaconda3libsite-packagestensorflowpythonframeworkops.py", line 1128, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): logits and labels must be same size: logits_size=[1,2] labels_size=[1,3]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_1, Reshape_2)]]


Process finished with exit code 1






You must be logged in to post. Please login or register an account.



simple google the error:

http://stackoverflow.com/questions/34519423/tensorflow-error-logits-and-labels-must-be-same-size

-kingfitz 8 years ago

You must be logged in to post. Please login or register an account.